﻿using System.Runtime.Caching;
Dictionary<string, object> dict = new Dictionary<string, object>();
MemoryCache cache = new MemoryCache("mycache");
string key = "mykey";
cache.Set(key, "myvalue", DateTimeOffset.Now.AddSeconds(30));//数据有效期
while (true)
{
    var obj = cache.Get(key);
    if (obj == null)
    {
        Console.WriteLine("缓存数据不存在");
    }
    else
    {
        Console.WriteLine(obj.ToString());
    }
    Task.Delay(5000).Wait();
}
Console.ReadLine();
//cache.Remove(key);
